package MapReduce.Demo8_TemperatureCountByMonth;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @Author lixinlei
 * @Date 2023/3/21 9:07
 */
public class TemperatureCountByMonthCombiner extends Reducer<Text, IntWritable,Text,IntWritable> {
    IntWritable temperatureCount = new IntWritable();

    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Reducer<Text, IntWritable, Text, IntWritable>.Context context) throws IOException, InterruptedException {

        int tempSum = 0;
        for (IntWritable value : values) {
            tempSum += value.get();
        }

        temperatureCount.set(tempSum);

        context.write(key,temperatureCount);

    }
}
